package com.qcby.Controller;

import com.qcby.Entity.Demo;
import com.qcby.Service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/Demo")
public class DemoController {

    @Autowired
    private DemoService demoService;

    @CrossOrigin
    @GetMapping("/getDemoById")
    public Demo getDemoById(@PathVariable Integer id) {
        return demoService.selectByPrimaryKey(id);
    }

    @CrossOrigin
    @PostMapping
    public Demo createCity(@RequestBody Demo demo) {
        demoService.insert(demo);
        return demo;
    }

    @CrossOrigin
    @PutMapping("/updateDemo")
    public Demo updateDemo(@PathVariable Integer id, @RequestBody Demo demo) {
        demo.setId(id);
        demoService.updateByPrimaryKey(demo);
        return demo;
    }

    @DeleteMapping("/deleteDemo")
    public void deleteDemo(@PathVariable Integer id) {
        demoService.deleteByPrimaryKey(id);
    }

}